package com.zzl.boot.bigevent.mapper;

import com.zzl.boot.bigevent.pojo.article;
import com.zzl.boot.bigevent.pojo.tag;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface articleTagMapper {
    @Select("insert into article_tag_ref(article_id,tag_id) values (#{articleId},#{tagId})")
    void add(Integer articleId, Integer tagId);

    @Select("select * from tag where " +
            "id=any(select tag_id from article_tag_ref where article_id=#{articleId})")
    List<tag> getList(Integer articleId);

    //修改文章对应的标签
    @Select("update article_tag_ref set tag_id=#{tagId} where article_id=#{articleId} and tag_id!=#{tagId}")
    void update(Integer articleId, Integer tagId);

    @Select("delete from article_tag_ref where article_id=#{articleId}")
    void del(Integer articleId);

    @Select("select count(*) from  article_tag_ref where tag_id=#{id}")
    Integer artilceCount(Integer id);
    //获取标签对应的文章列表
    @Select("select * from article where " +
            "id=any(select article_id from  article_tag_ref where tag_id=#{id})")
    List<article> getArticleList(Integer id);
}
